//
//  ICMRepairEventSearchTableViewCell.m
//  ICrEAM
//
//  Created by FoREVer_SaD on 16/11/2.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "ICMRepairEventSearchTableViewCell.h"

@interface ICMRepairEventSearchTableViewCell ()

@property (nonatomic, strong) UILabel *eventNameLabel;

@property (nonatomic, strong) UILabel *eventOrderLabel;

@property (nonatomic, strong) UILabel *workingTimeLabel;

@property (nonatomic, strong) UILabel *deviationLabel;

@end

@implementation ICMRepairEventSearchTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        UIView *repairEventCellView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ActualWidth(924), ActualHeight(95))];
        repairEventCellView.backgroundColor = BackgroundColor_Gray;
        [self.contentView addSubview:repairEventCellView];
        
        UIButton *eventOperateButton = [UIButton buttonWithType:UIButtonTypeCustom];
        eventOperateButton.frame = CGRectMake(ActualWidth(31), ActualHeight(27), ActualWidth(33), ActualHeight(33));
        [eventOperateButton setImage:[UIImage imageNamed:@"btn_activity_notchoose"] forState:UIControlStateNormal];
        [eventOperateButton setImage:[UIImage imageNamed:Appointment_ActivityChoose] forState:UIControlStateSelected];
        [repairEventCellView addSubview:eventOperateButton];
        self.eventOperateButton = eventOperateButton;
        
        UIView *blankView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ActualWidth(96), ActualHeight(95))];
        blankView.backgroundColor = [UIColor clearColor];
        [repairEventCellView addSubview:blankView];
        
        UIView *firstEventSep = [[UIView alloc] initWithFrame:CGRectMake(ActualWidth(96), 0, 1, repairEventCellView.height)];
        firstEventSep.backgroundColor = [UIColor whiteColor];
        [repairEventCellView addSubview:firstEventSep];
        
        UILabel *eventNameLabel = [self createLabelWithText:@"" frame:CGRectMake(firstEventSep.rightEdge, ActualHeight(12), ActualWidth(420), ActualHeight(44))];
        eventNameLabel.font = BoldNaviFont;
        UILabel *eventOrderLabel = [self createLabelWithText:@"" frame:CGRectMake(firstEventSep.rightEdge, eventNameLabel.bottomEdge+ActualHeight(10), ActualWidth(420), ActualHeight(20))];
        eventOrderLabel.textColor = ContentTextColor_Gray;
        self.eventNameLabel = eventNameLabel;
        self.eventOrderLabel = eventOrderLabel;
        
        [repairEventCellView addSubview:eventNameLabel];
        [repairEventCellView addSubview:eventOrderLabel];
        
        UIView *secondEventSep = [[UIView alloc] initWithFrame:CGRectMake(eventNameLabel.rightEdge, 0, 1, repairEventCellView.height)];
        secondEventSep.backgroundColor = [UIColor whiteColor];
        [repairEventCellView addSubview:secondEventSep];
        
        UILabel *workingTimeLabel = [self createLabelWithText:@"" frame:CGRectMake(secondEventSep.rightEdge, ActualHeight(37), ActualWidth(155), ActualHeight(16))];
        [repairEventCellView addSubview:workingTimeLabel];
        self.workingTimeLabel = workingTimeLabel;
        
        UIView *thirdEventSep = [[UIView alloc] initWithFrame:CGRectMake(workingTimeLabel.rightEdge, 0, 1, repairEventCellView.height)];
        thirdEventSep.backgroundColor = [UIColor whiteColor];
        [repairEventCellView addSubview:thirdEventSep];
        
        UILabel *deviationLabel = [self createLabelWithText:@"" frame:CGRectMake(thirdEventSep.rightEdge, workingTimeLabel.y, repairEventCellView.width-thirdEventSep.rightEdge, ActualHeight(16))];
        [repairEventCellView addSubview:deviationLabel];
        self.deviationLabel = deviationLabel;
        
        UIView *seperator = [[UIView alloc] initWithFrame:CGRectMake(0, 0, repairEventCellView.width, 1.0)];
        seperator.backgroundColor = [UIColor whiteColor];
        [self addSubview:seperator];
    }
    return self;
}

- (void)setupLabelsWithModel:(ICMRepairMaintenanceModel *)model{
    self.model = model;
    self.eventNameLabel.text = model.LABOUR_NAME;
    self.eventOrderLabel.text = model.LABOUR_CODE;
    self.workingTimeLabel.text = model.STD_LABOUR_HOUR;
    self.deviationLabel.text = model.OFFSET_DESC;
    if ([model.LABOUR_HOUR_EDIT isEqualToString:@"12781002"]) {
        
    }
}

- (UILabel *)createLabelWithText:(NSString *)text frame:(CGRect)frame{
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = text;
    label.font = ContentFont;
    label.textColor = ContentTextColor_Black;
    label.textAlignment = NSTextAlignmentCenter;
    return label;
}

@end
